Imports System.ComponentModel

<Description("Bazova trida pro wrapper tridy.")> _
Public MustInherit Class WrapperBase
	Implements IWrapper, IDisposable

    <Description("Nativni (COM+) objekt.")> _
    Private m_WrappedObject As Object

    <Description("Nativni (COM+) objekt.")> _
    Protected Property WrappedObject() As Object
        Get
            Return Me.m_WrappedObject
        End Get
        Set(ByVal Value As Object)
            Me.m_WrappedObject = Value
        End Set
    End Property

    <Description("Vraci nativni (COM+) objekt.")> _
    Public Function GetWrappedObject() As Object Implements IWrapper.GetWrappedObject
        Return Me.WrappedObject
    End Function

    <Description("Pokud dva wrapper objekty obsahuji tu samou instanci nativniho (COM+) objektu, pak vraci true.")> _
    Public Overrides Function Equals(ByVal obj As Object) As Boolean
        Dim ret As Boolean = False

		ret = Object.ReferenceEquals(Me, obj)

        If ret = False And obj Is GetType(IWrapper) Then
            Dim wobj As IWrapper = CType(obj, IWrapper)

            Dim a As Object = Me.GetWrappedObject()
            Dim b As Object = wobj.GetWrappedObject()

			ret = Object.ReferenceEquals(a, b)
        End If

        Return ret
	End Function

	Public Overrides Function GetHashCode() As Integer
		Return MyBase.GetHashCode()
	End Function

	Protected Overridable Sub DisposeInternal()
		Dim nativeObject As Object = Me.m_WrappedObject
		Me.m_WrappedObject = Nothing
	End Sub

	Public Sub Dispose() Implements IDisposable.Dispose
		Me.DisposeInternal()
	End Sub

	<Description("Konstruktor.")> _
	Public Sub New(<Description("Nativni (COM+) objekt.")> ByVal nativeObject As Object)
		If nativeObject Is Nothing Then Throw New ArgumentNullException("nativeObject")

		Me.WrappedObject = nativeObject
	End Sub
End Class
